// SPDX-FileCopyrightText: 2023-2025 Sangfor Technologies Inc.
// SPDX-License-Identifier: Mulan PSL v2
package com.geniusai.aip.auth.domain;

import lombok.Data;

/**
 * 创建用户时添加相应的EnvoyFilter解决与kubeflow ml-pipeline通信的问题
 *
 * @author lp58607
 * @date 2021/11/4
 */
@Data
public class EnvoyFilter {
    private String namespace;

    public String getEnvoyFilter() {
        return "{\"apiVersion\": \"networking.istio.io/v1alpha3\" , \"kind\": \"EnvoyFilter\"," +
                "\"metadata\":" +
                "  {\"name\": \"add-header\", " +
                "  \"namespace\": \"" + namespace + "\"}, " +
                "\"spec\":" +
                "  {\"configPatches\":" +
                "    [{\"applyTo\": \"VIRTUAL_HOST\", " +
                "    \"match\":" +
                "      {\"context\": \"SIDECAR_OUTBOUND\", " +
                "      \"routeConfiguration\":" +
                "        {\"vhost\":" +
                "          {\"name\": \"ml-pipeline.kubeflow.svc.cluster.local:8888\", " +
                "          \"route\":" +
                "            {\"name\": \"default\"}}}}, " +
                "    \"patch\":" +
                "      {\"operation\": \"MERGE\", " +
                "      \"value\":" +
                "        {\"request_headers_to_add\":" +
                "          [{\"append\": true, " +
                "          \"header\":" +
                "            {\"key\": \"kubeflow-userid\", " +
                "            \"value\": \"" + namespace + "@sangfor.com" + "\"}}]}}}], " +
                "  \"workloadSelector\":" +
                "    {\"labels\":" +
                "      {\"istio.io/rev\": \"default\"}}}}";
    }
}
